from PIL import Image
import os

def compress_image(input_path, output_path, quality=85):
    """
    压缩图片并保存到指定路径。

    :param input_path: 输入图片路径
    :param output_path: 输出图片路径
    :param quality: 图片质量，范围1-100，默认为85
    """
    # 打开图片
    image = Image.open(input_path)

    # 保存压缩后的图片
    image.save(output_path, 'JPEG', quality=quality)

    print(f"图片已保存至 {output_path}，质量参数为 {quality}")

# 示例用法
input_image_path = 'd:/user/01422219/我的文档/My Pictures/tmp.png'
import time
output_image_path = f'd:/user/01422219/我的文档/My Pictures/{int(time.time())}.png'
compress_image(input_image_path, output_image_path)
